package logging;

import java.util.Date;
 
public class Record{
 
    private String message;
    private Level level;
    private String formatConsole;
    private String formatFile;
    private String separator;
    private String loggerName;
    private Throwable throwable;
    private String typeFormat; 
    private Date date;
    private String messageFormatted;
    
    public Record(String message, Level level, String loggerName) {
    	this.message = message;
    	this.level = level;
    	this.formatConsole = LoggerConstants.formatDefault;
    	this.formatFile = LoggerConstants.formatDefault;
    	this.separator = LoggerConstants.separatorDefault;
    	this.loggerName = loggerName;
    	this.throwable = null;
    	this.date = new Date();
    	this.typeFormat = LoggerConstants.typeFormatDefault;
    	this.messageFormatted = message;
    }
    
    /*
     * return typeFormat
     */
    public String getTypeFormat(){
    	return this.typeFormat;
    }
 
    /*
     * return message with associated throwable if throwable != null
     */
    public String getMessage() {
    	if (getThrowable() != null){
    		return message + getStackTraceThrowable();
    	}
    	return message;
    }
    
    public String getMessageWithoutThrowable(){
    	return message;
    }
 
    /*
     * return stacktrace from throwable
     */
    private String getStackTraceThrowable() {
    	String output = "";
    	StackTraceElement[] stackTrace = getThrowable().getStackTrace();
    	for (StackTraceElement element : stackTrace){
    		output += " " + element.toString();
    	}
    	return output;
	}

	/* 
     * return message level
 	 */
    public Level getLevel() {
        return level; 
    }

    /*
     * return message formatConsole
     */
    public String getFormatConsole() {
        return formatConsole;
    }
    
    /*
     * return message formatFile
     */
    public String getFormatFile() {
        return formatFile;
    }
 
    /*
     * return message separator
     */
    public String getSeparator() {
    	return separator;
    }
 
    /*
     * return message throwable
     */
    public Throwable getThrowable(){
		return throwable;
    }
 
    /*
     * return logger name
     */
    public String getLoggerName() {
        return loggerName; 
    }
 
    public void setTypeFormat(String typeFormat){
    	this.typeFormat = typeFormat;
    }
    
    public void setFormatConsole(String format) {
        this.formatConsole = format; 
    }
    
    public void setFormatFile(String format) {
        this.formatFile = format; 
    }
 
    public void setSeparator(String separator) {
        this.separator = separator;        
    }
 
    public void setLoggerName(String loggerName) {
    	this.loggerName = loggerName; 
    }
 
    public void setThrowable(Throwable throwable){
        this.throwable = throwable;
    }
    
    public Date getDate(){
    	return this.date;
    }
   
    public void setMessage(String message){
    	this.messageFormatted = message;
    }
    
    public String getMessageFormatted(){
    	return this.messageFormatted;
    }
   
} 